package com.example.springbootshiro.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.springbootshiro.dao.BuildProductMapper;
import com.example.springbootshiro.entity.BuildProduct;
import com.example.springbootshiro.service.BuildProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BuildProductServiceImpl implements BuildProductService {


    @Autowired
    private BuildProductMapper buildProductMapper;

    @Override
    public int add(BuildProduct buildProduct) {
        return buildProductMapper.insert(buildProduct);
    }

    @Override
    public int delete(BuildProduct buildProduct) {
        QueryWrapper<BuildProduct> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", buildProduct.getId());
        return buildProductMapper.delete(queryWrapper);
    }

    @Override
    public int update(BuildProduct buildProduct) {
        return buildProductMapper.updateById(buildProduct);
    }

    @Override
    public List<BuildProduct> selectAll(String param1, String param2, String param3) {
        QueryWrapper<BuildProduct> queryWrapper = new QueryWrapper<>();
        if (param1 != null && !"".equals(param1)){
            queryWrapper.and(QueryWrapper -> QueryWrapper.like("customer", param1));
        }
        if (param2 != null && !"".equals(param2)){
            queryWrapper.and(QueryWrapper -> QueryWrapper.gt("time", param2));
        }
        if (param3 != null && !"".equals(param3)){
            queryWrapper.and(QueryWrapper -> QueryWrapper.lt("time", param3));
        }
        List<BuildProduct> buildProducts = buildProductMapper.selectList(queryWrapper);
        return buildProducts;
    }
}
